# 导包
from API.login import LoginAPI
import pytest

test_data=[
    ("admin","HM_2023_test","成功",200,200),
    ("","HM_2023_test","错误",200,500),
    ("11222666","HM_2023_test","错误",200,500),
]
class TestLogin:
    uuid=None
    # 1前置条件
    def setup_method(self):
        # 实例化对象
        self.login_api=LoginAPI()
        res_v=self.login_api.get_verify_code()
        print(res_v.json())
        TestLogin.uuid=res_v.json()["uuid"]
        print(TestLogin.uuid)

    # 2后置条件
    def teardown(self):
        pass
        # 1登陆成功

    @pytest.mark.parametrize("username,pwd,msg_in,status_code,js_code",test_data)
    def test01_login_success(self,username,pwd,msg_in,status_code,js_code):

        test_data={

        "username":username,
        "password":pwd,
        "code":"2",
        "uuid":TestLogin.uuid
        }
        res_login_success=self.login_api.login(test_data=test_data)
        print(res_login_success.json())

        # 断言响应码为200
        assert res_login_success.status_code==status_code
        #断言包含"成功二字"
        assert msg_in in res_login_success.text
        #断言响应json的code里面为200
        assert js_code==res_login_success.json()["code"]

    #
    #     # 2 登陆失败(用户名为空)
    # def test02_login_fail(self):
    #     test_data = {
    #
    #         "username": "",
    #         "password": "HM_2023_test",
    #         "code": "2",
    #         "uuid": TestLogin.uuid
    #     }
    #     res_login_fail = self.login_api.login(test_data=test_data)
    #     print(res_login_fail.json())
    #     # 断言响应码为200
    #     assert res_login_fail.status_code == 200
    #     # 断言包含"成功二字"
    #     assert "错误" in res_login_fail.text
    #     # 断言响应json的code里面为200
    #     assert 500 == res_login_fail.json()["code"]
    #     #3 登陆失败(用户名为不存在)
    # def test03_login_fail(self):
    #     test_data = {
    #
    #         "username": "111111777",
    #         "password": "HM_2023_test",
    #         "code": "2",
    #         "uuid": TestLogin.uuid
    #     }
    #     res_login_fail = self.login_api.login(test_data=test_data)
    #     print(res_login_fail.json())
    #     # 断言响应码为200
    #     assert res_login_fail.status_code == 200
    #     # 断言包含"成功二字"
    #     assert "错误" in res_login_fail.text
    #     # 断言响应json的code里面为200
    #     assert 500 == res_login_fail.json()["code"]



